package framework.customer;

import java.util.ArrayList;
import java.util.List;

import framework.BaseManager;
import framework.account.IAccount;

/**
 * This Class responsible to store basic information about customer
 * and list of his accounts it can be extended by subclasses 
 * @author Abdulaziz Ergashev
 *
 */
public abstract class BaseCustomer implements ICustomer{
	protected List<IAccount> accounts;
	public BaseCustomer(String name, String street,String city, String zip,String email,String state){
		this.name = name;
		this.street = street;
		this.city = city;
		this.zip = zip;
		this.email = email;
		this.state = state;
		accounts = new ArrayList<IAccount>(); 
	}
	
	public List<IAccount> getAaccounts() {
		return accounts;
	}

	/*
	 * adds account to customer, one customer may have multiple accounts
	 * @see framework.customer.ICustomer#addAccount(framework.account.IAccount)
	 */
	public void addAccount(IAccount acc) {
		accounts.add(acc);
		acc.setCustomer(this);
		//will register its observers if there any subscribed
		BaseManager.getInstance().registerObservers(acc);
	}
	
	/*
	 * method looks for customers account with given account number
	 * if there is no such it returns null
	 * @see framework.customer.ICustomer#getAccount(java.lang.String)
	 */
	public IAccount getAccount(String accountNumber) {
		for(IAccount acc:accounts){
			if(acc.getAccountNo().equals(accountNumber)){
				return acc;
			}
		}
		return null;
	}


	/**
	 * @uml.property  name="name"
	 */
	protected String name;
	/**
	 * @uml.property  name="street"
	 */
	protected String street;
	/**
	 * @uml.property  name="city"
	 */
	protected String city;
	/**
	 * @uml.property  name="state"
	 */
	protected String state;
	/**
	 * @uml.property  name="zip"
	 */
	protected String zip;
	/**
	 * @uml.property  name="email"
	 */
	protected String email;

	/**
	 * @return
	 * @uml.property  name="name"
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 * @uml.property  name="name"
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return
	 * @uml.property  name="street"
	 */
	public String getStreet() {
		return street;
	}

	/**
	 * @param street
	 * @uml.property  name="street"
	 */
	public void setStreet(String street) {
		this.street = street;
	}

	/**
	 * @return
	 * @uml.property  name="city"
	 */
	public String getCity() {
		return city;
	}

	/**
	 * @param city
	 * @uml.property  name="city"
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @return
	 * @uml.property  name="state"
	 */
	public String getState() {
		return state;
	}

	/**
	 * @param state
	 * @uml.property  name="state"
	 */
	public void setState(String state) {
		this.state = state;
	}

	/**
	 * @return
	 * @uml.property  name="zip"
	 */
	public String getZip() {
		return zip;
	}

	/**
	 * @param zip
	 * @uml.property  name="zip"
	 */
	public void setZip(String zip) {
		this.zip = zip;
	}

	/**
	 * @return
	 * @uml.property  name="email"
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 * @uml.property  name="email"
	 */
	public void setEmail(String email) {
		this.email = email;
	}

    public enum Type{
        Company, Personal
	}
}